package com.dkts.oil.exception;


import com.dkts.oil.constant.ResultCode;
import com.dkts.oil.web.vo.response.Result;
import lombok.Getter;
import lombok.Setter;

/**
 * @author heguanglong
 * @date 2018/04/23
 */
public class OilException extends RuntimeException {

    private static final long serialVersionUID = 1001L;

    /**
     * 返回对象，该对象中包含异常原因，异常码，成功等信息
     */
    @Setter
    @Getter
    private Result result;

    /**
     * 公共类，初始化返回对象，服务器异常，一般需要后面进一步处理
     */
    public OilException(int code, String msg) {
        this.result = new Result(code, msg);
    }

    public OilException(ResultCode resultCode) {
        this.result = Result.error(resultCode);
    }

    public OilException(Result result) {
        this.result = result;
    }

    public OilException(String errMsg) {
        this.result = Result.errorMsg(errMsg);
    }

    public static OilException paramError(String msg) {
        return new OilException(Result.paramError(msg));
    }

    public static OilException fileTypeError(String msg) {
        return new OilException(Result.fileTypeError(msg));
    }
}
